<template>
  <div class='container'>
    <el-dialog
  title="提示"
  :visible="dialogFormVisible"
  width="30%"
  :before-close="handleClose">
 <el-form
        :rules="rules"
        ref="dataForm"
        :model="formBase"
        label-width="19%"
      >
        <el-form-item
          :required="true"
          label="学科名称"
          prop="subjectName"
        >
          <el-input v-model="formBase.subjectName"></el-input>
        </el-form-item>
        <el-switch
    style="display: block"
    v-model="formBase.isFrontDisplay"
    active-color="#13ce66"
    inactive-color="#ff4949"
    inactive-text="是否显示">
  </el-switch>
      </el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="handleClose">取 消</el-button>
    <el-button type="primary" @click="createData">确 定</el-button>
  </span>
</el-dialog>
  </div>
</template>

<script>
import { Message } from 'element-ui'
import { update, add } from '@/api/hmmm/subjects.js'
export default {
  props: ['formBase', 'dialogFormVisible'],
  data () {
    return {
      rules: {
        subjectName: [{ required: true, message: '请输入学科名称', trigger: 'blur' }]
      }
    }
  },
  methods: {
    // 退出
    handleClose () {
      this.$emit('update:dialogFormVisible', false)
      this.$refs.dataForm.resetFields()
    },
    // 提交表单
    async createData () {
      try {
        console.log(1)
        console.log(this.formBase)
        await this.$refs.dataForm.validate()
        console.log(2)
        if (this.formBase.id) {
          await update(this.formBase)
          this.$emit('newDataes', this.formBase)
        } else {
          await add(this.formBase)
          this.$emit('newDataes', this.formBase)
        }
        this.handleClose()
      } catch (error) {
        Message.error('*号为必填项!')
      }
    }
  }
}
</script>

<style scoped lang='less'></style>
